<template>
  <div class="box">
    <h1>C组件，演示辅助函数的使用,{{ count }}----{{ num3 }}</h1>
    <el-button type="primary" @click="handlePlus">数字+</el-button>
    <el-button type="primary" @click="handleMinu(10)">数字-</el-button>
    <div v-for="item in goods">名称：{{ item.name }} 价格:{{ item.price }}</div>
  </div>
</template>

<script>
import { mapState, mapMutations, mapGetters } from "vuex";
import { myMapMutations } from "./my-map";
export default {
  computed: {
    // count() {
    //   return this.$store.state.count.num;
    // },
    // goods() {
    //   return this.$store.state.good.goods;
    // },
    ...mapState({
      count: (state) => state.count.num,
      goods: (state) => state.good.goods,
    }),
    ...mapGetters({
      num3: "count/num3",
    }),
  },
  methods: {
    // 方法1：
    // handlePlus() {
    //   this.$store.commit("count/increment");
    // },
    // handleMinu(n) {
    //   this.$store.commit("count/decrement",n);
    // },
    // 方法2：使用官方mutations
    // ...mapMutations({
    //   handlePlus: "count/increment",
    //   handleMinu: "count/decrement",
    // }),
    // 方法3：分析辅助函数的封装原理
    ...myMapMutations({
      handlePlus: "count/increment",
      handleMinu: "count/decrement",
    }),
  },
};
</script>

<style lang="scss" scoped>
.box {
  width: 50%;
  border: 1px solid #333;
  height: 500px;
}
</style>
